package com.example.Controller;


import org.python.core.PyFunction;
import org.python.core.PyList;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 测试调用python程序接口
 */
@RestController
public class TestController {
    @RequestMapping("/test")
    public String test(){

        PythonInterpreter interpreter = new PythonInterpreter();

        Random random = new Random();
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<10;i++){
            list.add(random.nextInt(100));
        }

        interpreter.execfile("D:\\qq\\Files\\icpc\\icpc_1.py");

        PyFunction pyFunction = interpreter.get("my_sort",PyFunction.class);
        PyObject pyObject = pyFunction.__call__(new PyList(list));

        return pyObject.toString();
    }
}
